﻿#include "appsettings.h"

QMutex AppSettings::mutex;
QScopedPointer<AppSettings> AppSettings::instance;

AppSettings::AppSettings()
{
    qDebug() << "AppSettings()";
}

AppSettings::~AppSettings()
{
    qDebug() << "~AppSettings()";
}

void AppSettings::init()
{
    QSettings settings("AppSettings.ini", QSettings::IniFormat);
    settings.beginGroup("sqlite");
    m_sqlite_dbUsername = settings.value("db_username").toString();
    m_sqlite_dbPwd = settings.value("db_pwd").toString();
    m_sqlite_dbDbname = settings.value("db_dbname").toString();
    settings.endGroup();
}

AppSettings &AppSettings::getInstance()
{
    if (instance.isNull()) {
        mutex.lock();
        if (instance.isNull()) {
            instance.reset(new AppSettings());
            instance.data()->init();
        }
        mutex.unlock();
    }

    return *instance.data();
}
